<< define "user/index.html" >>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>用户管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <link rel="stylesheet" href="/static/css/mbgadmin.css">
    <script src="/static/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <script type="text/javascript" src="/static/js/mbgadmin.js"></script>
</head>
<body>
<div class="layui-card-body">
    <form class="layui-form" action="">
        <div class="layui-input-inline layui-show-xs-block padding-bottom-10">
            <input class="layui-input" placeholder="用户名" name="username">
        </div>
        <div class="layui-input-inline layui-show-xs-block padding-bottom-10">
            <input class="layui-input" placeholder="手机号" name="mobile">
        </div>
        <div class="layui-input-inline layui-show-xs-block padding-bottom-10">
            <select name="status">
                <option value="">状态</option>
                <option value="1">正常</option>
                <option value="0">禁用</option>
            </select>
        </div>
        <div class="layui-input-inline layui-show-xs-block padding-bottom-10">
            <button class="layui-btn" lay-submit="" lay-filter="sreach">
                <i class="layui-icon">&#xe615;</i>搜索
            </button>
        </div>
    </form>
    <hr>
    <button class="layui-btn" onclick="xadmin.open('添加用户','/users/create')" id="create">
        <i class="layui-icon"></i>添加用户
    </button>
    <table id="admin" lay-filter="admin"></table>
</div>
<script type="text/html" id="user-roles">
    {{#  layui.each(d.roles, function(index, item){ }}
    <span>{{= item.Name }}</span>;
    {{#  }); }}
</script>
<script>
    layui.use(['table', 'form','layer'], function () {
        var table = layui.table;
        var form = layui.form;
        var layer = layui.layer

        //初始化表格
        table.render({
            elem: '#admin',
            url: '/users/lists',
            page: true,
            cols: [[
                {field: 'ID', title: 'ID'},
                {field: 'name', title: '用户名'},
                {
                    field: 'role_name', title: '拥有角色', templet:'#user-roles'
                },
                {field: 'phone', title: '手机号'},
                {field: 'age', title: '年龄'},
                {field: 'sex', title: '性别',templet:function (d){
                        if(d.sex === 1){
                            return '<span style="color: blue">♂</span>';
                        } else {
                            return '<span style="color: pink">♀</span>';
                        }
                    }},
                {field: 'email', title: '邮箱'},
                {field: 'deviceInfo', title: '登录设备信息'},
                {field: 'clientIp', title: '登录IP'},
                {
                    field: 'status', title: '状态', templet: function (d) {
                        return GoStatusFormatHTML(d.status)
                    }
                },
                {
                    field: 'created_user', title: '添加人', templet: function (d) {
                        return d.created_user.name
                    }
                },
                {
                    field: 'updated_user', title: '更新人', templet: function (d) {
                        return d.updated_user.name
                    }
                },
                {
                    field: 'loginOutTime', title: '最后登录时间', templet: function (d) {
                        return GoTimeFormat(new Date(d.loginOutTime))
                    }
                },
                {
                    field: 'CreatedAt', title: '添加时间', templet(d) {
                        return GoTimeFormat(new Date(d.CreatedAt))
                    }
                },
                {
                    field: 'UpdatedAt', title: '修改时间', templet: function (d) {
                        return GoTimeFormat(new Date(d.CreatedAt))
                    }
                },
                {field: 'experience', title: '操作', toolbar: '#button', width: 220},
            ]],
        });

        //监听表格事件
        table.on('tool(admin)', function (obj) {
            var data = obj.data;
            var layEvent = obj.event;

            if (layEvent === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    layer.close(index);
                    $.get("/users/del/" + data.ID, function (result) {
                        layer.msg(result.msg);
                        if (result.code === 0) {
                            obj.del();
                        }
                    });
                });
            } else if (layEvent === 'edit') {
                layer.open({
                    id:'edit_users',
                    type:2,
                    title:"编辑用户",
                    skin: 'layui-layer-molv',
                    closeBtn:2,
                    anim:5,
                    area: ['680px', '520px'],
                    maxmin: false, //开启最大化最小化按钮
                    content:"/users/edit",
                    success:function (layero,index){
                        // 获取子页面的iframe
                        var iframe = window['layui-layer-iframe'+index];
                        // 向子页面的全局函数child传参
                        iframe.child(data);
                    },
                })
            }else if (layEvent ==='reset'){
                layer.confirm('重置默认密码为123456', function (index) {
                    layer.close(index);
                    $.get("/users/reset/" + data.ID, function (result) {
                        layer.msg(result.msg);
                    });
                });
            }
        });

        //搜索
        form.on('submit(sreach)', function (data) {
            table.reload('admin', {
                where: data.field,
                page: {
                    curr: 1 //重新从第 1 页开始
                }
            });
            return false;
        });

        // if ({{{.but.Edit}}}===0 && {{{.but.Edit}}}===0){
        //     $("#button #edit").remove();
        // }


    })
</script>
<script type="text/html" id="button">
    <a class="layui-btn layui-btn-xs" lay-event="edit" id="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" id="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="reset" id="reset" style="background-color: royalblue">重置密码</a>
</script>
</body>
</html>
<< end >>